<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Up File</title>
</head>
Thông tin File Upload<br />
<?php 
if(isset($_POST["ok"]))
{
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
     || ($_FILES["file"]["type"] == "image/png")
      || ($_FILES["file"]["type"] == "image/jpg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 200000))
    {
        if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
        else
        {
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            $_SESSION["fileImg"] = $_FILES["file"]["name"];
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";            
            if (file_exists("Upload/". $_FILES["file"]["name"]))
            {
                echo "File: ".$_FILES["file"]["name"] . ": File này đã tồn tại!!";
            }
            else
            {
            move_uploaded_file($_FILES["file"]["tmp_name"],"Upload/". $_FILES["file"]["name"]);
            echo "<img src=Upload/". $_FILES["file"]["name"]." width=105 height=105/></br>";
            echo "Stored in: Upload/". $_FILES["file"]["name"];
            }
        }
    }
    else
    {
    echo "Invalid file";
    }
}
else
echo 'File not found.';
?>
<br />
<script type="text/javascript" language="javascript">
function updateParent() {
    opener.document.formParent.imageDefault.value = document.childForm.cf1.value;
    self.close();
    return false;
}
</script>
<a href="javascript:void(0)" onclick="javascript:history.go(-1)">Go back</a>
<form name="childForm" onSubmit="return updateParent();">
<input name="cf1" type="hidden" value="<?php echo $_SESSION["fileImg"] ?>"/>
<input type="SUBMIT" value="Close"/>
</form>
<body>
</body>
</html>
